package it.getta.vicinometro.adapter;

import it.getta.vicinometro.R;
import it.getta.vicinometro.utils.FileCache;
import it.getta.vicinometro.utils.ImageLoader;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class LazyAdapter extends BaseAdapter {
    
    private Context mContext;
    private String[] mData;
    private static LayoutInflater mInflater=null;
    public ImageLoader mImageLoader; 
    
    public LazyAdapter(Context c, FileCache fileCache) {
        mContext = c;
        mData = new String[0];
        mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mImageLoader=new ImageLoader(mContext, fileCache);
    }

    public int getCount() {
        return mData.length;
    }

    public String getItem(int position) {
        return mData[position];
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View view=convertView;
        if(convertView==null)
            view = mInflater.inflate(R.layout.gallery_item, null);
        ImageView image=(ImageView)view.findViewById(R.id.gallery_image);
        mImageLoader.DisplayImage(mData[position], image);
        return view;
    }
    
    public void setData(String [] data) {
    	this.mData = data;
    }
    
    public String[] getData() {
    	return mData;
    }
    
}